import cPickle as pickle

class PSO:
    def __init__(self, data=None):
            if data is not None:
                if isinstance(data, str) or isinstance(data, unicode):
                    pickleData = pickle.loads(data)
                    self.data = pickleData[1]
                    self.type = pickleData[0]
                else:
                    self.data = data[1]
                    self.type = data[0]
            else:
                self.data = {}
                self.type = None

    def __str__(self):
        return str([self.type, self.data])

    def set(self, key, data):
        self.data[key] = data

    def get(self, key):
        try:
            return self.data[key]
        except:
            return None
        
    def getPickle(self):
        return pickle.dumps([self.type, self.data], pickle.HIGHEST_PROTOCOL)
								
    def getData(self):
	  return [self.type, self.data]
